<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title>提问列表</title>
		<link rel="stylesheet" href="../../css/mui.min.css"/>
		<link rel="stylesheet" href="../../css/base.css">
	</head>
	<style>
		.mui-table-view-cell > a:not(.mui-btn) {
			padding: 10px;
		}
		/*					.mui-table-view-cell:active {
		 background: #fff;
		 }*/
		.cell-title {
			height: 22px;
		}
		.cell-subtitle, .message_content {
			height: 20px;
		}
		.right-div {
			width: 70px;
			float: right;
		}
		.left-div {
			margin-right: 70px;
		}
		.message_title {
			width: 90%;
			color: #222222
		}
		.right-tag {
			text-align: right;
		}
		/*.mui-table-view .mui-media-object {*/
		/*margin-top: 4px;*/
		/*}*/
		.discuss-del {
			width: 18px;
			margin-right: 0px;
		}
		.discuss-del-div {
			text-align: right;
			height: 40px;
		}
		.redPointMessage {
			top: 8px;
			left: 44px;
			/*display:;*/
		}
	</style>
	<body>
		<div id="mian">
			<ul class="mui-table-view" id="stulist">
				<!--<li class="mui-table-view-cell mui-media" onclick="openexam()">
				<a href="javascript:;"> <img class="mui-media-object mui-pull-left" src="../../image/icon_taolun1.png" >
				<div class="mui-media-body">
				<div class="right-div">
				<p class="mui-ellipsis base_grey content_p right-tag">
				未参与
				</p>
				</div>
				<div class="left-div">
				<p class="mui-ellipsis base_dark_grey font16 cell-title">
				<span class="message_title"> 讨论名称 </span>
				</p>
				<p class="mui-ellipsis base_grey font14 content_p cell-subtitle">
				<span class="file_submit_time"> 2017-01-02 14:20 </span>
				</p>
				</div>
				</div> </a>
				</li>-->
			</ul>
		</div>
		<div class="noSign" hidden="hidden" id="noData">
			<img src="../../image/icon_img.png" width="60%">
			<p class="font16 top_15 base_dark_grey" >
				暂无调查
			</p>
		</div>
		<div class="loadFailure" hidden="hidden" id="noNet">
			<img src="../../image/icon_img01.png" width="60%">
			<p class="" >
				数据加载失败
			</p>
			<p>
				请检查您的网络
			</p>
			<button type="button"  onclick="refreshData()"class="mui-btn mui-btn-outlined">
				重新加载
			</button>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script src="../../script/jquery.min.js"></script>
	<script src="../../script/common.js"></script>
	<script src="../../script/MD5.js"></script>
	<script src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/timeStampTool.js"></script>
	<script type="text/javascript">
		var page = 1;
		var rows = 10;
		var refreshCount = 0;
		var arr = new Array();
		var firstLoad = true;
		apiready = function() {
			setRefreshHeader();
			setPullUpRefresh();
			sendBuriedNotifi('0', '学生端调查列表页', '176');
			loadNewData();
			ReceNotifi();
		}
		function sendBuriedNotifi(busionessid, pagetype, pagetypeid) {
			var userinfo = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				uname : $api.getStorage('cfnetppusername'),
			}
			var data = {
				busionessid : busionessid,
				pagetype : pagetype,
				pagetypeid : pagetypeid,
				sourceurl : api.pageParam.sourceurl,
				sourcetitle : api.pageParam.sourcetitle,
				accesspageurl : window.location.pathname,
				accesspagetitle : document.title,
				userinfo : userinfo
			}
			SendBehaviorTrajectoriesNotifi_Study(data);
		}
		//接收通知
		function ReceNotifi() {
			api.addEventListener({
				name : 'RefreshReasearchList'
			}, function(ret, err) {
				refreshData();
			});
			api.addEventListener({
				name : 'pushMessage_classroomMessage'
			}, function(ret, err) {
				var notifiJid = ret.value.jid;
				if (notifiJid == $api.getStorage('cfnetppjxid')) {
					var DC_TYPE = ret.value.type;
					if (DC_TYPE == 10010) {
						loadNewData();
					}
				}
			});
		}

		//加载新数据
		function loadNewData() {
			page = 1;
			loadData();
		}

		//加载更多数据
		function loadMoreData() {
			page++;
			loadData();
		}

		//下拉刷新
		function setRefreshHeader() {
			api.setRefreshHeaderInfo({
				visible : true,
				bgColor : '#ccc',
				textColor : '#fff',
				textDown : '下拉刷新...',
				textUp : '松开刷新...',
				showTime : true
			}, function(ret, err) {
				loadNewData();
			});
		}

		// 上拉加载
		function setPullUpRefresh() {
			api.addEventListener({
				name : 'scrolltobottom'
			}, function(ret, err) {
				if (refreshCount >= rows) {
					loadMoreData();
				}
			});
		}

		//重新加载按钮响应事件
		function refreshData() {
			firstLoad = true;
			loadNewData();
		}

		//获取数据
		function loadData() {
			if (firstLoad == true) {
				showProgress();
				firstLoad = false;
			}
			pageParam = api.pageParam;
			var params = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				tid : 3,
				page : page,
				rows : rows,
				cid : api.pageParam.cid,
				pid : api.pageParam.pid,
			};
			cfnetppPOST(url_stuGetActivelist, params, true, function(data, status) {
				hideProgress();
				api.refreshHeaderLoadDone();
				if (status == 'success') {
					if (data.code == 200) {
//						console.log(JSON.stringify(data));
						var students = data.data;
						refreshCount = data.data.length;
						if (students != '' && students.constructor == Array && students.length > 0) {
							$('#noData').hide();
							$('#noNet').hide();
							$('#mian').show();
							arr = students;
							writelist(students, students.length);
						} else {
							if (page == 1) {
								$('#noData').show();
								$('#noNet').hide();
							}
						}
					} else if (data.code = 108) {
						if (page == 1) {
							$('#noData').show();
							$('#noNet').hide();
							$('#stulist').html('');
						}
					} else {
						if (page == 1) {
							$('#noData').show();
							$('#noNet').hide();
							$('#stulist').html('');
						}
					}
				} else {
					$('#noData').hide();
					$('#noNet').show();
					$('#stulist').html('');
				}
			});
		}

		//填充ui布局
		function writelist(listdata, len) {
			var htmls = '';
			var status = '';
			for (var i = 0; i < len; i++) {
				var data = listdata[i];
				var starttime = data.starttime;
				var timeString = '';
				if (starttime == null||starttime == 0) {
					timeString = timeWithStamp3(data.createtime);
				} else {
					timeString = timeWithStamp3(starttime);
				}
				//0未开始,1是进行中,2已结束,3删除;当前活动状态
				// var activity_status = data.activestatus;
				// if (activity_status == null || activity_status == 0) {//未开始
				// 	status = '未开始';
				// } else if (activity_status == 1) {//
				// 	if (data.userstatus == null || data.userstatus == 0) {//未开始
				// 		status = '未参加';
				// 	} else if (data.userstatus == 10) {//已经
				// 		status = '已参加';
				// 	}
				// } else if (activity_status == 2) {//已结束
				// 	status = '已结束';
				// }
				// var new_message = "";
				// var s = data.status;
				// console.log("status : " + s);
				// if (s != undefined && s != null && s == 0) {
				// 	new_message = '<div id="redPoint' + data.id + '" class="redPointMessage"></div>';
				// }
				var new_message = "";
				var activestatus = data.activestatus;
				var statusString = '未开始';
				if (activestatus == 1) {//已开始
					if (data.userstatus == 10) {//已参加
						statusString = '已参与';
					} else {
						statusString = '进行中';
						new_message = '<div id="redPoint' + data.id + '" class="redPointMessage"></div>';
					}
				} else if (activestatus == 2) {//已结束
					statusString = '已结束';
				} else if (activestatus == 3) {//已删除
					statusString = '已删除';
				}
				var strhtml = '<li class="mui-table-view-cell mui-media"  onclick="openexam(' + data.id + ',' + activestatus + ',' + data.userstatus + ',' + "'" + data.name + "'" + ')">' + '<a href="javascript:;" style="position:relative;">' + new_message + '<img class="mui-media-object mui-pull-left" src="../../icon/icon_research.png" >' + '<div class="mui-media-body">' + '<div class="right-div">' + '<p class="mui-ellipsis base_grey content_p right-tag font12" style="height: 42px;line-height: 42px;">' + statusString + '</p>' + '</div>' + '<div class="left-div" >' + '<p class="mui-ellipsis base_dark_grey font14 cell-title">' + '<span class="message_title">' + data.name + '</span>' + '</p>' + '<p class="mui-ellipsis base_grey font12 content_p cell-subtitle top_10">' + '<span class="message_content">' + '<span class="file_submit_time">' + timeString + '</span>' + '</span>' + '</p>' + '</div>' + '</div>' + '</a>' + '</li>';
				htmls = htmls + strhtml;
			}
			if (page == 1) {
				$('#stulist').html(htmls);
			} else {
				$('#stulist').append(htmls);
			}
		}

		//打开调查考试页
		function openexam(id, activity_status, userstatus, name) {
			//			uploadReadStatus(id);
			// $("#redPoint" + id).hide();
			api.openWin({useWKWebView:true,
				name : 'Student_ResearchExam',
				url : 'Student_ResearchExam.html',
				pageParam : {
					id : id,
					activity_status : activity_status,
					name : name,
					userstatus : userstatus,
					sourceurl : window.location.pathname,
					sourcetitle : document.title
				}
			});
		}

		/*
		 修改课堂信息状态
		 */
		function uploadReadStatus(id) {
			var params = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				iid : id,
				tid : 3
			};
			cfnetppPOST(url_classroomMessageSetStatus, params, false, function(data, status) {
			});
		}
	</script>
</html>